'use strict';
//引入jwt
import jwt from 'jsonwebtoken'
//读取secret标记码
let secret = think.config("hxc.secret");
//读取token有效期
let expiresIn = think.config("hxc.expiresIn");
export default class extends think.service.base {
  /**
   * init
   * @return {}         []
   */
  init(...args){
    super.init(...args);
  }
  verifyUser(username,password){
      return username == "admin" && password=="654321";
  }
  createToken(userinfo) {
      return jwt.sign(userinfo, secret);
  }

    /**
     * @description 验证票据
     * @param {Object} token 用户请求token
     * @return 返回 错误或者解密过的token
     */
    verifyToken(token) {
        if (token) {
            try {
                return jwt.verify(token, secret);
            } catch (err) {
                //票据验证失败,需要提示需要重新登录
                return "fail";
            }
        }
        return "fail";
    }

}